import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/1/26.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
///自定义按钮
class ButtonBorderWidget extends StatelessWidget {
  //按钮上的文字
  final String buttonLabel;

  //是否填充背景
  final bool hasBorder;

  //点击事件回调
  final GestureTapCallback onTap;
  final String heroTag;

  ButtonBorderWidget({
    Key key,
    @required this.buttonLabel,
    this.hasBorder = false,
    this.heroTag,
    this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (heroTag != null) {
      return Hero(
        tag: heroTag,
        child: buildMaterial(context),
      );
    }
    return buildMaterial(context);
  }

  Material buildMaterial(BuildContext context) {
    return Material(
      color: Colors.transparent,
      child: Ink(
        //边框
        decoration: BoxDecoration(
          //点击事件高亮的边框圆角
          borderRadius: BorderRadius.circular(30),
          //边框设置
          border: hasBorder
              ? Border.all(
                  color: Colors.white,
                  width: 2.0,
                )
              : Border.fromBorderSide(BorderSide.none),
        ),
        //事件监听回调
        child: buildInkWell(context),
      ),
    );
  }

  InkWell buildInkWell(BuildContext context) {
    return InkWell(
      //事件回调
      onTap: onTap,
      //点击的水波纹与高亮颜色 与Ink设置的背景圆角一致
      borderRadius: BorderRadius.circular(10),
      //按钮样式
      child: Container(
        height: 60.0,
        child: Center(
          child: Text(
            //文本内容
            buttonLabel,
            //文本样式
            style: TextStyle(
              //文本颜色
              color: Colors.white,
              //加粗
              fontWeight: FontWeight.w500,
              //文字大小
              fontSize: 20.0,
            ),
          ),
        ),
      ),
    );
  }
}
